// 2025/2/18: 首个版本

using System;
using ASEva.UIEto;
using Eto.Drawing;
using Eto.Forms;

namespace CommonSource
{
    class MultiSelect : DialogPanel
    {
        public MultiSelect(string title, string[] options, int[] defaultSelectIndices, Icon icon = null)
        {
            Icon = icon;
            Title = title;
            SetFixMode(400, 300, true);

            SelectedIndices = defaultSelectIndices;

            var itemsChecked = new bool[options.Length];
            for (int i = 0; i < defaultSelectIndices.Length; i++)
            {
                var index = defaultSelectIndices[i];
                if (index >= 0 && index < itemsChecked.Length)
                {
                    itemsChecked[index] = true;
                }
            }

            var layout = this.SetContentAsColumnLayout();

            var listBox = layout.AddControl(new CheckableListBox(), true);
            listBox.AddItems(options, itemsChecked);

            layout.AddButton("OK", false).Click += delegate
            {
                SelectedIndices = listBox.GetCheckedIndices();
                Close();
            };
        }

        public int[] SelectedIndices { get; private set; }
    }
}